#pragma once



/****************************
*         CONTROLS          *
****************************/

static int webcamSetControlCallback_wdm( struct v4l2_ctrl* );

static const struct v4l2_ctrl_ops webcamControlOps_wdm = {
	.s_ctrl = webcamSetControlCallback_wdm,
};



//TODO: Merge these into V4L API.


#define V4L2_CID_GREEN_BALANCE   (V4L2_CID_BASE+31)
#define V4L2_CID_NIGHT_MODE      (V4L2_CID_BASE+33)


/* 2007-09-09 TJ Ensure names are identical to uvcvideo,
 * so user applications aren't confused by differing results for UVC queries */



/* TODO: Use our own internal control IDs, instead of crap unmerged ones. */
static struct webcam_control r5u870_wdm_ctrls[] = {

	[R5U870_WDM_CTRL_BRIGHTNESS] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_BRIGHTNESS,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Brightness",
			.min = 0,
			.max = 127,
			.step = 1,
			.def = 63,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_BRIGHTNESS,
	},
	[R5U870_WDM_CTRL_CONTRAST] = { 
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_CONTRAST,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Contrast",
			.min = 0,
			.max = 127,
			.step = 1,
			.def = 63,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_CONTRAST,
	},
	[R5U870_WDM_CTRL_SATURATION] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_SATURATION,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Saturation",
			.min = 0,
			.max = 127,
			.step = 1,
			.def = 63,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_SATURATION,
	},
	[R5U870_WDM_CTRL_SHARPNESS] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_SHARPNESS,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Sharpness",
			.min = 0,
			.max = 127,
			.step = 1,
			.def = 63,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_SHARPNESS,
	},
	[R5U870_WDM_CTRL_HUE] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_HUE,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Hue",
			.min = -180,
			.max = 180,
			.step = 1,
			.def = 0,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_HUE,
	},
	[R5U870_WDM_CTRL_GAMMA] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_GAMMA,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Gamma",
			.min = 0,
			.max = 500,
			.step = 1,
			.def = 100,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_GAMMA,
	},
	[R5U870_WDM_CTRL_BACKLIGHT_COMP_500] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_BACKLIGHT_COMPENSATION,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Backlight Compensation",
			.min = 0,
			.max = 500,
			.step = 1,
			.def = 250,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_BACKLIGHT_COMP,
	},
	[R5U870_WDM_CTRL_BACKLIGHT_COMP_500_DEF1] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_BACKLIGHT_COMPENSATION,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Backlight Compensation",
			.min = 0,
			.max = 500,
			.step = 1,
			.def = 1,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_BACKLIGHT_COMP,
	},
	[R5U870_WDM_CTRL_BACKLIGHT_COMP_X1834] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_BACKLIGHT_COMPENSATION,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Backlight Compensation",
			.min = 0,
			.max = 2,
			.step = 1,
			.def = 1,
			.flags = V4L2_CTRL_FLAG_SLIDER
		},
		.reg = R5U870_REG_BACKLIGHT_COMP_2,
	},
	[R5U870_WDM_CTRL_WB_RED] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_RED_BALANCE,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "White Balance Red",
			.min = 0,
			.max = 255,
			.step = 1,
			.def = 127,
			.flags = 0
		},
		//.query_fn = r5u870_query_ctrl,
		.reg = R5U870_REG_WB_RED_EX,
		//.auto_offset = offsetof(struct driverInstance, vh_auto_wb)
	},
	[R5U870_WDM_CTRL_WB_GREEN] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_GREEN_BALANCE,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "White Balance Green",
			.min = 0,
			.max = 255,
			.step = 1,
			.def = 127,
			.flags = 0
		},
		//.query_fn = r5u870_query_ctrl,
		.reg = R5U870_REG_WB_GREEN_EX,
		//.auto_offset = offsetof(struct driverInstance, vh_auto_wb)
	},
	[R5U870_WDM_CTRL_WB_BLUE] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_BLUE_BALANCE,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "White Balance Blue",
			.min = 0,
			.max = 255,
			.step = 1,
			.def = 127,
			.flags = 0
		},
		//.query_fn = r5u870_query_ctrl,
		.reg = R5U870_REG_WB_BLUE_EX,
		//.auto_offset = offsetof(struct driverInstance, vh_auto_wb)
	},
	[R5U870_WDM_CTRL_WB_AUTO] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_AUTO_WHITE_BALANCE,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "Auto White Balance",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 1,
			.flags = V4L2_CTRL_FLAG_UPDATE
		},
		.reg = R5U870_REG_WB_AUTO_EX,
		//.is_auto = 1,
		//.val_offset = offsetof(struct driverInstance, vh_auto_wb)
	},
	[R5U870_WDM_CTRL_AUTO_EXPOSURE] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_EXPOSURE_AUTO,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "Auto Exposure Control",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 1,
			.flags = 0
		},
		.reg = R5U870_REG_AEC_EX,
		//.is_auto = 1,
		//.val_offset = offsetof(struct driverInstance, vh_aec)
	},
	[R5U870_WDM_CTRL_EXPOSURE] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_EXPOSURE,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Exposure",
			.min = 0,
			.max = 511,
			.step = 1,
			.def = 255,
			.flags = 0
		},
		//.query_fn = r5u870_query_ctrl,
		.reg = R5U870_REG_EXPOSURE_EX,
		//.auto_offset = offsetof(struct driverInstance, vh_aec)
	},
	[R5U870_WDM_CTRL_AUTO_GAIN] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_AUTOGAIN,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "Auto Gain Control",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 1,
			.flags = 0
		},
		.reg = R5U870_REG_AGC_EX,
		//.is_auto = 1,
		//.val_offset = offsetof(struct driverInstance, vh_agc)
	},
	[R5U870_WDM_CTRL_GAIN] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_GAIN,
			.type = V4L2_CTRL_TYPE_INTEGER,
			.name = "Gain",
			.min = 0,
			.max = 127,
			.step = 1,
			.def = 63,
			.flags = 0
		},
		//.query_fn = r5u870_query_ctrl,
		.reg = R5U870_REG_GAIN_EX,
		//.auto_offset = offsetof(struct driverInstance, vh_agc)
	},
	[R5U870_WDM_CTRL_POWERLINE] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_POWER_LINE_FREQUENCY,
			.type = V4L2_CTRL_TYPE_MENU,
			.name = "Power Line Frequency",
			.min = 0,
			.max = 2,
			//.step = 1,
			.def = 0,
			.flags = 0,
			.qmenu = powerline_frequency_menu_item_names
		},
		.reg = R5U870_REG_POWERLINE_EX,
	},
	[R5U870_WDM_CTRL_VFLIP] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_VFLIP,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "V-Flip",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 0,
			.flags = 0
		},
		.reg = R5U870_REG_VFLIP_EX,
	},
	[R5U870_WDM_CTRL_VFLIP_DEFAULTON] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_VFLIP,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "V-Flip",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 1,
			.flags = 0
		},
		.reg = R5U870_REG_VFLIP_EX,
	},
	[R5U870_WDM_CTRL_HFLIP] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_HFLIP,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "H-Flip",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 0,
			.flags = 0
		},
		.reg = R5U870_REG_HFLIP_EX,
	},
	[R5U870_WDM_CTRL_PRIVACY] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_PRIVACY,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "Privacy",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 0,
			.flags = 0
		},
		.reg = R5U870_REG_PRIVACY_EX,
	},
	[R5U870_WDM_CTRL_NIGHTMODE] = {
		.control = {
			.ops = &webcamControlOps_wdm,
			.id = V4L2_CID_NIGHT_MODE,
			.type = V4L2_CTRL_TYPE_BOOLEAN,
			.name = "Night Mode",
			.min = 0,
			.max = 1,
			.step = 1,
			.def = 0,
			.flags = 0
		},
		//2007-09-09 TJ Add missing IOCTL query
		//.query_fn = r5u870_query_ctrl, 
		.reg = R5U870_REG_NIGHT_MODE_EX,
	},
};
